package com.example.permissionsystem1_1.businessFunction.controller.impl;

import com.example.permissionsystem1_1.businessFunction.controller.converter.TestControllerConverter;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.testReqDto.*;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.testRspDto.*;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.testReqModel.*;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.testRspModel.*;
import com.example.permissionsystem1_1.businessFunction.service.interfaces.TestService;
import com.example.permissionsystem1_1.common.businessFunction.BaseController;
import com.example.permissionsystem1_1.common.util.RspResult;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试类
 * 后面这里的基础接口方法,都应该抽取成公共方法放到Base类中或者是用代码生成器生成模板代码(而不需要手写)
 */
@RestController
@RequestMapping("/test")
@ApiModel("测试")
public class TestController extends BaseController {
    @Autowired
    private TestService testService;
    @ApiOperation(value = "测试", notes = "测试", httpMethod = "GET")
    @RequestMapping(value = "/test1",method = RequestMethod.GET)
    public String test1(){
        return "test1";
    }

    @ApiOperation(value = "新增一条记录", notes = "新增一条记录", httpMethod = "POST")
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public RspResult<TestInsertRspDto> insert(@Validated @RequestBody TestInsertReqDto reqDto){
        TestInsertReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
        TestInsertRspModel rspModel=testService.insert(reqModel);
        TestInsertRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "批量新增多条记录", notes = "批量新增多条记录", httpMethod = "POST")
    @RequestMapping(value = "/insertBatch",method = RequestMethod.POST)
    public RspResult<TestInsertBatchRspDto> insertBatch(@Validated @RequestBody TestInsertBatchReqDto reqDto){
        TestInsertBatchReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
        TestInsertBatchRspModel rspModel=testService.insertBatch(reqModel);
        TestInsertBatchRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "根据id删除一条记录", notes = "根据id删除一条记录", httpMethod = "POST")
    @RequestMapping(value = "/deleteById",method = RequestMethod.POST)
    public RspResult<TestDeleteByIdRspDto> deleteById(@Validated @RequestBody TestDeleteByIdReqDto reqDto){
        TestDeleteByIdReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
        TestDeleteByIdRspModel rspModel=testService.deleteById(reqModel);
        TestDeleteByIdRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "根据给定的字段值删除符合条件的多条记录", notes = "根据给定的字段值删除符合条件的多条记录", httpMethod = "POST")
    @RequestMapping(value = "/deletes",method = RequestMethod.POST)
    public RspResult<TestDeletesRspDto> deletes(@Validated @RequestBody TestDeletesReqDto reqDto){
        TestDeletesReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
        TestDeletesRspModel rspModel=testService.deletes(reqModel);
        TestDeletesRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "根据id集合删除多条记录", notes = "根据id集合删除多条记录", httpMethod = "POST")
    @RequestMapping(value = "/deleteBatchByIds",method = RequestMethod.POST)
    public RspResult<TestDeleteBatchByIdsRspDto> deleteBatchByIds(@Validated @RequestBody TestDeleteBatchByIdsReqDto reqDto){
        TestDeleteBatchByIdsReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
        TestDeleteBatchByIdsRspModel rspModel=testService.deleteBatchByIds(reqModel);
        TestDeleteBatchByIdsRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "根据id修改一条记录", notes = "根据id修改一条记录", httpMethod = "POST")
    @RequestMapping(value = "/updateById",method = RequestMethod.POST)
    public RspResult<TestUpdateByIdRspDto> updateById(@Validated @RequestBody TestUpdateByIdReqDto reqDto){
        TestUpdateByIdReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
        TestUpdateByIdRspModel rspModel=testService.updateById(reqModel);
        TestUpdateByIdRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "根据指定的byTestPo中的属性为选择条件,按照setTestPo中的属性进行修改符合条件的多条记录", notes = "根据指定的byTestPo中的属性为选择条件,按照setTestPo中的属性进行修改符合条件的多条记录", httpMethod = "POST")
    @RequestMapping(value = "/updates",method = RequestMethod.POST)
    public RspResult<TestUpdatesRspDto> updates(@Validated @RequestBody TestUpdatesReqDto reqDto){
        TestUpdatesReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
        TestUpdatesRspModel rspModel=testService.updates(reqModel);
        TestUpdatesRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "根据指定多个ids,来批量修改多条记录", notes = "根据指定多个ids,来批量修改多条记录", httpMethod = "POST")
    @RequestMapping(value = "/updateBatchByIds",method = RequestMethod.POST)
    public RspResult<TestUpdateBatchByIdsRspDto> updateBatchByIds(@Validated @RequestBody TestUpdateBatchByIdsReqDto reqDto){
        TestUpdateBatchByIdsReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
        TestUpdateBatchByIdsRspModel rspModel=testService.updateBatchByIds(reqModel);
        TestUpdateBatchByIdsRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "根据指定id查询一条记录", notes = "根据指定id查询一条记录", httpMethod = "POST")
    @RequestMapping(value = "/selectById",method = RequestMethod.POST)
    public RspResult<TestSelectByIdRspDto> selectById(@Validated @RequestBody TestSelectByIdReqDto reqDto){
        TestSelectByIdReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
        TestSelectByIdRspModel rspModel=testService.selectById(reqModel);
        TestSelectByIdRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "根据指定的条件查询符合条件的多条记录", notes = "根据指定的条件查询符合条件的多条记录", httpMethod = "POST")
    @RequestMapping(value = "/selects",method = RequestMethod.POST)
    public RspResult<TestSelectsRspDto> selects(@Validated @RequestBody TestSelectsReqDto reqDto){
        TestSelectsReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
        TestSelectsRspModel rspModel=testService.selects(reqModel);
        TestSelectsRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "根据多个id查询多条记录", notes = "根据多个id查询多条记录", httpMethod = "POST")
    @RequestMapping(value = "/selectBatchByIds",method = RequestMethod.POST)
    public RspResult<TestSelectBatchByIdsRspDto> selectBatchByIds(@Validated @RequestBody TestSelectBatchByIdsReqDto reqDto){
        TestSelectBatchByIdsReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
        TestSelectBatchByIdsRspModel rspModel=testService.selectBatchByIds(reqModel);
        TestSelectBatchByIdsRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "分页查询多条记录", notes = "分页查询多条记录", httpMethod = "POST")
    @RequestMapping(value = "/selectPage",method = RequestMethod.POST)
    public RspResult<TestSelectPageRspDto> selectPage(@Validated @RequestBody TestSelectPageReqDto reqDto){
        TestSelectPageReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
        TestSelectPageRspModel rspModel=testService.selectPage(reqModel);
        TestSelectPageRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

}
